var vm = new Vue({
    el: '#app',
    created: function () {
        var that = this;

        $.ajax({
            'url': '/trainPlatform/famousInternet/search',
            'success': function (resp) {
                if (resp.success) {
                    that.collegeList = resp.data;
                }
            }
        });
    },
    data: {
        collegeList: [],
        kw: '',
        kw_: ''
    },
    computed: {},
    methods: {
        'edit': function (i) {
            var that = this;

            mdui.prompt('院校名称编辑', '院校名称', function (text) {
                    $.ajax({
                        'url': '/trainPlatform/famousInternet/update',
                        'data': {
                            'oldname': that.collegeList[i],
                            'newname': text
                        },
                        'success': function (resp) {
                            if (resp.success) {
                                mdui.snackbar({
                                    message: '修改成功'
                                });

                                Vue.set(that.collegeList, i, text);
                            } else {
                                mdui.snackbar({
                                    message: resp.msg
                                });
                            }
                        }
                    });
                }, function (text) {
                },
                {
                    'confirmText': '确定',
                    'cancelText': '取消',
                    'defaultValue': this.collegeList[i]
                });
        },
        'del': function (i) {
            var that = this;

            mdui.dialog({
                title: '删除提醒',
                content: '确定删除' + this.collegeList[i] + '吗?',
                buttons: [
                    {
                        text: '取消'
                    },
                    {
                        text: '确认',
                        onClick: function (inst) {
                            $.ajax({
                                'url': "/trainPlatform/famousInternet/delete",
                                'data': {
                                    name: that.collegeList[i]
                                },
                                'success': function (resp) {
                                    if (resp.success) {
                                        that.collegeList.splice(i, 1);
                                    } else {
                                        alert(resp.msg);
                                    }
                                }
                            });
                        }
                    }
                ]
            });
        },
        'searchInput': function () {
            if (this.kw_ == this.kw) {
                return;
            }

            var that = this;

            $.ajax({
                'url': '/trainPlatform/famousInternet/search',
                'data': {
                    'kw': this.kw
                },
                'success': function (resp) {
                    if (resp.success) {
                        that.collegeList = resp.data;
                    }
                }
            });

            this.kw_ = this.kw;
        },
        'importNewCollege': function () {
            var that = this;

            mdui.prompt('新企业导入', '企业名称', function (text) {
                    $.ajax({
                        'url': '/trainPlatform/famousInternet/add',
                        'data': {
                            'name': text
                        },
                        'success': function (resp) {
                            if (resp.success) {
                                mdui.snackbar({
                                    message: '插入成功'
                                });

                                that.collegeList.push(text);
                            } else {
                                mdui.snackbar({
                                    message: resp.msg
                                });
                            }
                        }
                    });
                }, function (text) {
                },
                {
                    'confirmText': '确定',
                    'cancelText': '取消',
                    'defaultValue': ''
                });
        }
    },
    components: {}
});